package equivalence

import (
	"gitee.com/meilier/flower/image"
	"gitee.com/meilier/flower/platform"
)

// Specv1 is v1 satisfiability algorithm
type Specv1 string

func (s *Specv1) Name() string {
	return "specv1"
}

func (s *Specv1) Version() string {
	return "v0.1"
}

func (s *Specv1) Equals(r image.RequireSpec, p platform.ProviderSpec) bool {
	if r.KernelVersion != "" && p.KernelVersion != "" {
		if r.KernelVersion <= p.KernelVersion {
			return true
		}
	}

	// TODO: sort or buckets
	matches := 0
	for _, rSyscall := range r.Syscalls {
		for _, pSyscall := range p.Syscalls {
			if rSyscall == pSyscall {
				matches++
			}
		}
	}

	return matches == len(r.Syscalls)
}
